package com.lk.web.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.commons.collections.CollectionUtils;
import org.assertj.core.util.Lists;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 角色表
 *
 * @author Aspirin
 * @since 2020-06-21
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class SysRole implements Serializable {
  private static final long serialVersionUID = 1L;
  /** 角色 ID */
  @TableId(value = "id", type = IdType.AUTO)
  private Long id;
  /** 角色名称 */
  private String name;
  /** 角色说明 */
  private String remark;

  private LocalDateTime createDate;
  private LocalDateTime updateDate;

  /** 存储当前角色的权限资源对象集合 修改角色时用到 */
  @TableField(exist = false)
  private List<SysPermission> perList = Lists.newArrayList();
  /** 存储当前角色的权限资源ID集合 修改角色时用到 */
  @TableField(exist = false)
  private List<Long> perIds = Lists.newArrayList();

  public List<Long> getPerIds() {
    if (CollectionUtils.isNotEmpty(perList)) {
      perIds = Lists.newArrayList();
      for (SysPermission per : perList) {
        perIds.add(per.getId());
      }
    }
    return perIds;
  }
}
